home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / date / addial.int < prev    next >
Text File  |  1996-04-08  |  12KB  |  333 lines

  1. {$G+,X+,F+}
  2.  
  3. {Conditional defines that may affect this unit}
  4. {$I AWDEFINE.INC}
  5.  
  6. {*********************************************************}
  7. {*                   ADDIAL.PAS 1.01                     *}
  8. {*        Copyright (c) TurboPower Software 1995         *}
  9. {*                 All rights reserved.                  *}
  10. {*********************************************************}
  11.  
  12. unit AdDial;
  13.   {-Dialer window}
  14.  
  15. interface
  16.  
  17. uses
  18.   SysUtils,
  19.   WinTypes,
  20.   WinProcs,
  21.   Messages,
  22.   Classes,
  23.   Graphics,
  24.   Controls,
  25.   Forms,
  26.   Dialogs,
  27.   StdCtrls,
  28.   Buttons,
  29.   OoMisc,
  30.   AdMisc,
  31.   AdExcept,
  32.   AdPort,
  33.   AdModem;
  34.  
  35. type
  36.   {TApdModemDialer options}
  37.   TDialerOption  = (mdAbortOnVoice, mdAbortOnBusy, mdAbortOnNoCarrier,
  38.                     mdAbortOnNoDialtone, mdAbortOnError);
  39.   TDialerOptions = Set of TDialerOption;
  40.  
  41.   TDialResult = (drNone, drDialing, drConnected, drAborted);
  42.  
  43. const
  44.   {TApdModemDialer settings}
  45.   DefDialerOptions = [mdAbortOnNoDialtone, mdAbortOnError];
  46.  
  47.   {TApdDialerDialog settings}
  48.   NumStatusLines  = 13;
  49.   DefMaxDialTries = 10;
  50.   DefRetrySecs    = 60;
  51.  
  52. type
  53.   {component for dialing phone numbers}
  54.   TApdCustomModemDialer = class(TComponent)
  55.   protected {private}
  56.     {.Z+}
  57.     FModem              : TApdCustomModem;      {modem to use for dialing}
  58.     FPhoneNumber        : String;               {phone number to dial}
  59.     FMaxDialTries       : Integer;              {max # of dial attempts}
  60.     FRetrySecs          : Integer;              {seconds between dial retries}
  61.     FDialerOptions      : TDialerOptions;       {options for dialing}
  62.     FDialResult         : TDialResult;          {result of dial attempt}
  63.     FDialing            : Boolean;              {TRUE if dialer active}
  64.     FRetryStart         : TNotifyEvent;         {before dial retry starts}
  65.     FRetryCount         : TConnectCountEvent;   {when retry counter ticks}
  66.     FRetryEnd           : TNotifyEvent;         {when dial retry is finished}
  67.     FCycleDial          : TNotifyEvent;         {when dial attempt cycled}
  68.     FDialStart          : TNotifyEvent;         {at beginning of dial}
  69.     FConnect            : TNotifyEvent;         {when connection established}
  70.     FDialCount          : TConnectCountEvent;   {when dial timer ticks}
  71.     FGotLineSpeed       : TLineSpeedEvent;      {when connect speed detrmnd}
  72.     FBusy               : TNotifyEvent;         {when modem returns busy}
  73.     FVoice              : TNotifyEvent;         {when modem returns voice}
  74.     FError              : TNotifyEvent;         {when modem returns error}
  75.     FNoCarrier          : TNotifyEvent;         {when modem returns ncarrier}
  76.     FNoDialTone         : TNotifyEvent;         {when modem returns ndialtn}
  77.     FDialTimedOut       : TNotifyEvent;         {when dial attempt times out}
  78.     FConnectionEstablished : TNotifyEvent;      {when connection is established}
  79.     FTooManyTries       : TNotifyEvent;         {when too many dials tried}
  80.     FRetrying           : Boolean;              {TRUE if retrying dial attempt}
  81.  
  82.     {dialing data}
  83.     ComPort             : TApdCustomComPort;    {communications port}
  84.     DialTry             : Integer;              {current dial try}
  85.     DialIdx             : Integer;              {index of dial start timer trig}
  86.  
  87.     {retry data}
  88.     Cycling             : Boolean;              {TRUE if cycling dial attempt}
  89.     RetryIdx            : Integer;              {index of retry count trigger}
  90.     RetryWait           : Integer;              {# secs left until retry}
  91.  
  92.     {saved event handlers}
  93.     SaveTriggerTimer    : TTriggerTimerEvent;
  94.     SaveModemConnect    : TNotifyEvent;
  95.     SaveDialCount       : TConnectCountEvent;
  96.     SaveGotLineSpeed    : TLineSpeedEvent;
  97.     SaveModemBusy       : TNotifyEvent;
  98.     SaveModemVoice      : TNotifyEvent;
  99.     SaveModemError      : TNotifyEvent;
  100.     SaveModemNoCarrier  : TNotifyEvent;
  101.     SaveModemNoDialTone : TNotifyEvent;
  102.     SaveDialTimedOut    : TNotifyEvent;
  103.     SaveOnByeBye        : TNotifyEvent;
  104.  
  105.     procedure Notification(AComponent : TComponent; Operation : TOperation); override;
  106.  
  107.     procedure PrepareDialing;
  108.       {-Start a timer to trigger the beginning of a dial attempt}
  109.     procedure RetryDial;
  110.       {-Retry the last dial attempt, if possible}
  111.     procedure RetryDone;
  112.       {-Cleanup after a retry countdown}
  113.  
  114.     {dialer event handlers}
  115.     procedure DialerTriggerTimer(Sender : TObject; TriggerHandle : Word);
  116.     procedure DialerModemConnect(Sender : TObject);
  117.     procedure DialerDialCount(Sender : TObject; Remaining : Word);
  118.     procedure DialerGotLineSpeed(Sender : TObject; Speed : LongInt);
  119.     procedure DialerModemBusy(Sender : TObject);
  120.     procedure DialerModemVoice(Sender : TObject);
  121.     procedure DialerModemError(Sender : TObject);
  122.     procedure DialerModemNoCarrier(Sender : TObject);
  123.     procedure DialerModemNoDialTone(Sender : TObject);
  124.     procedure DialerDialTimedOut(Sender : TObject);
  125.     procedure DialerModemByeBye(Sender : TObject);
  126.  
  127.     procedure RetryStart; virtual;
  128.     procedure RetryCount; virtual;
  129.     procedure RetryEnd; virtual;
  130.     procedure CycleDial; virtual;
  131.     procedure DialStart; virtual;
  132.     procedure GotConnect; virtual;
  133.     procedure DialCount(Cnt : Word); virtual;
  134.     procedure GotLineSpeed(Speed : LongInt); virtual;
  135.     procedure GotBusy; virtual;
  136.     procedure GotVoice; virtual;
  137.     procedure GotError; virtual;
  138.     procedure GotNoCarrier; virtual;
  139.     procedure GotNoDialTone; virtual;
  140.     procedure DialTimedOut; virtual;
  141.     procedure ConnectionEstablished; virtual;
  142.     procedure TooManyTries; virtual;
  143.  
  144.     procedure SinkHooks;
  145.       {-Replace existing ComPort/Modem event handlers with dialer handlers}
  146.     procedure RemoveHooks;
  147.       {-Remove dialer event handlers and replace with originals}
  148.     procedure DialingFinished;
  149.       {-Dialing done: shut down dial attempt}
  150.     procedure ShutDownOnDestroy;
  151.       {-Clean up during the middle of a dial attempt}
  152.  
  153.   public
  154.     constructor Create(AOwner : TComponent); override;
  155.     destructor Destroy; override;
  156.     {.Z-}
  157.  
  158.     {dialing data}
  159.     property Modem : TApdCustomModem
  160.       read FModem write FModem;
  161.     property PhoneNumber : String
  162.       read FPhoneNumber write FPhoneNumber;
  163.     property MaxDialTries : Integer
  164.       read FMaxDialTries write FMaxDialTries default DefMaxDialTries;
  165.     property RetrySecs : Integer
  166.       read FRetrySecs write FRetrySecs default DefRetrySecs;
  167.     property DialerOptions : TDialerOptions
  168.       read FDialerOptions write FDialerOptions;
  169.     property DialResult : TDialResult
  170.       read FDialResult;
  171.     property Dialing : Boolean
  172.       read FDialing;
  173.     property Retrying : Boolean
  174.       read FRetrying;
  175.  
  176.     {events}
  177.     property OnRetryStart : TNotifyEvent
  178.       read FRetryStart write FRetryStart;
  179.     property OnRetryCount : TConnectCountEvent
  180.       read FRetryCount write FRetryCount;
  181.     property OnRetryEnd : TNotifyEvent
  182.       read FRetryEnd write FRetryEnd;
  183.     property OnCycleDial : TNotifyEvent
  184.       read FCycleDial write FCycleDial;
  185.     property OnDialStart : TNotifyEvent
  186.       read FDialStart write FDialStart;
  187.     property OnConnect : TNotifyEvent
  188.       read FConnect write FConnect;
  189.     property OnDialCount : TConnectCountEvent
  190.       read FDialCount write FDialCount;
  191.     property OnGotLineSpeed : TLineSpeedEvent
  192.       read FGotLineSpeed write FGotLineSpeed;
  193.     property OnBusy : TNotifyEvent
  194.       read FBusy write FBusy;
  195.     property OnVoice : TNotifyEvent
  196.       read FVoice write FVoice;
  197.     property OnError : TNotifyEvent
  198.       read FError write FError;
  199.     property OnNoCarrier : TNotifyEvent
  200.       read FNoCarrier write FNoCarrier;
  201.     property OnNoDialTone : TNotifyEvent
  202.       read FNoDialTone write FNoDialTone;
  203.     property OnDialTimedOut : TNotifyEvent
  204.       read FDialTimedOut write FDialTimedOut;
  205.     property OnConnectionEstablished : TNotifyEvent
  206.       read FConnectionEstablished write FConnectionEstablished;
  207.     property OnTooManyTries : TNotifyEvent
  208.       read FTooManyTries write FTooManyTries;
  209.  
  210.     {methods}
  211.     procedure Dial;
  212.     procedure Cycle;
  213.     procedure Extend(const ByHowMuch : Word);
  214.     procedure Abort;
  215.   end;
  216.  
  217.   TApdModemDialer = class(TApdCustomModemDialer)
  218.     {dialing data}
  219.     property Modem;
  220.     property PhoneNumber;
  221.     property MaxDialTries;
  222.     property RetrySecs;
  223.     property DialerOptions;
  224.  
  225.     {events}
  226.     property OnRetryStart;
  227.     property OnRetryCount;
  228.     property OnRetryEnd;
  229.     property OnCycleDial;
  230.     property OnDialStart;
  231.     property OnConnect;
  232.     property OnDialCount;
  233.     property OnGotLineSpeed;
  234.     property OnBusy;
  235.     property OnVoice;
  236.     property OnError;
  237.     property OnNoCarrier;
  238.     property OnNoDialTone;
  239.     property OnConnectionEstablished;
  240.     property OnTooManyTries;
  241.   end;
  242.  
  243.   {.Z+}
  244.   TDialerForm = class(TForm)
  245.     GroupBox1: TGroupBox;
  246.     Label1: TLabel;
  247.     Label2: TLabel;
  248.     Label3: TLabel;
  249.     Label4: TLabel;
  250.     Label5: TLabel;
  251.     Label6: TLabel;
  252.     Label7: TLabel;
  253.     Label8: TLabel;
  254.     Label9: TLabel;
  255.     Label10: TLabel;
  256.     Label11: TLabel;
  257.     Label12: TLabel;
  258.     Label13: TLabel;
  259.     CycleBtn: TBitBtn;
  260.     ExtendBtn: TBitBtn;
  261.     AbortBtn: TBitBtn;
  262.     procedure CycleBtnClick(Sender: TObject);
  263.     procedure ExtendBtnClick(Sender: TObject);
  264.     procedure AbortBtnClick(Sender: TObject);
  265.  
  266.   public
  267.     Labels   : array[1..NumStatusLines] of TLabel;
  268.     OnLabel  : Word;
  269.     Dialer   : TApdCustomModemDialer;
  270.     SaveTrig : TTriggerTimerEvent;
  271.     DialTrig : Integer;
  272.  
  273.     constructor Create(AOwner : TComponent); override;
  274.  
  275.     procedure AddStatusString(const St : String);
  276.       {-Put a status string in the display}
  277.     procedure AddResString(const ResID : Word);
  278.       {-Load a status string from a resource and display it}
  279.     procedure DoDial(const ADialer : TApdCustomModemDialer);
  280.       {-Begin dialing}
  281.  
  282.     {dialer event handlers}
  283.     procedure FrmRetryStart(Sender : TObject);
  284.     procedure FrmRetryCount(M : TObject; Remaining : Word);
  285.     procedure FrmRetryEnd(Sender : TObject);
  286.     procedure FrmDialStart(Sender : TObject);
  287.     procedure FrmConnect(Sender : TObject);
  288.     procedure FrmDialCount(M : TObject; Remaining : Word);
  289.     procedure FrmGotLineSpeed(M : TObject; Speed : LongInt);
  290.     procedure FrmBusy(Sender : TObject);
  291.     procedure FrmVoice(Sender : TObject);
  292.     procedure FrmError(Sender : TObject);
  293.     procedure FrmNoCarrier(Sender : TObject);
  294.     procedure FrmNoDialTone(Sender : TObject);
  295.     procedure FrmDialTimedOut(Sender : TObject);
  296.     procedure FrmTooManyTries(Sender : TObject);
  297.     procedure FrmConnectionEstablished(Sender : TObject);
  298.     procedure FrmTriggerTimer(CP : TObject; TriggerHandle : Word);
  299.   end;
  300.   {.Z-}
  301.  
  302.   TApdDialerDialog = class(TCommonDialog)
  303.   protected {private}
  304.     {.Z+}
  305.     FModem         : TApdCustomModem;
  306.     FPhoneNumber   : String;
  307.     FMaxDialTries  : Integer;
  308.     FRetrySecs     : Integer;
  309.     FDialerOptions : TDialerOptions;
  310.  
  311.     procedure Notification(AComponent : TComponent; Operation : TOperation); override;
  312.  
  313.   public
  314.     constructor Create(AOwner : TComponent); override;
  315.     {.Z-}
  316.  
  317.     function Execute : Boolean;
  318.  
  319.   published
  320.     {dialing data}
  321.     property Modem : TApdCustomModem
  322.       read FModem write FModem;
  323.     property PhoneNumber : String
  324.       read FPhoneNumber write FPhoneNumber;
  325.     property MaxDialTries : Integer
  326.       read FMaxDialTries write FMaxDialTries default DefMaxDialTries;
  327.     property RetrySecs : Integer
  328.       read FRetrySecs write FRetrySecs default DefRetrySecs;
  329.     property DialerOptions : TDialerOptions
  330.       read FDialerOptions write FDialerOptions;
  331.   end;
  332.  
  333.